package com.File;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class FileCopy {
    public static void main(String[] args) {
        //思路分析
        //1.创建输入流,读取文件
        //2.创建输出流,输出文件
        String filePath = "d:\\头像.jpg";
        String filePath1 = "e:\\头像.jpg";
        FileInputStream fileInputStream = null;
        FileOutputStream fileOutputStream = null;
        int readLen = 0;
        try {
            fileInputStream = new FileInputStream(filePath);
            fileOutputStream = new FileOutputStream(filePath1);
            byte buf[] = new byte[1024];
            while ((readLen = fileInputStream.read(buf)) != -1) {
                //要一边读一边写
                fileOutputStream.write(buf, 0, readLen);//一定要用这个
            }

            System.out.println("copy ok");
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (fileInputStream != null) {
                    fileInputStream.close();
                }
                if (fileOutputStream != null) {
                    fileOutputStream.close();
                }

            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
